﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Configuration;

using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;

using BuzzwordBingo.Interface;
using BuzzwordBingo.Game;

namespace BuzzwordBingo.ConsoleServer
{
    /// <summary>
    /// A small console app that acts as a WCF host.
    /// Service behaviour and persistence type can be configured.
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                IUnityContainer container = new UnityContainer().LoadConfiguration();
                var persistence = container.Resolve<IPersistenceService>();
                Engine engine = container.BuildUp<Engine>(new Engine(persistence));

                Uri endpoint = new Uri(ConfigurationManager.AppSettings["baseAddressSetup"]);
                ServiceHost host = new ServiceHost(engine, endpoint);

                host.Open();
                Console.WriteLine("BuzzwordBingo.Engine is running.. [press Enter to close]");
                Console.ReadLine();
                Console.WriteLine("closing..");
                host.Close();

                container.Dispose();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
    }
}
